<template>
	<view class="content">
		<view class="tabber_box flexs1">
			<view class="tabber_item" @click='clickbtn(1)' :class="{'chooseactive':typeindex==1}">
				<view>做题记录</view>
				<view class="title_line" v-show="typeindex==1"></view>
			</view>
			<view class="tabber_item" @click='clickbtn(2)' :class="{'chooseactive':typeindex==2}">
				<view>错题本</view>
				<view class="title_line" v-show="typeindex==2"></view>
			</view>
		</view>
		<scroll-view class="list_box" scroll-y="true" lower-threshold="50" @scrolltolower="AddPage">
			<!-- 做题记录 -->
			<block v-if="typeindex==1">
				<view class="none_msg" v-if="ExamList.length==0">
					<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
					<view class="none_title">暂无信息</view>
				</view>
				<view class="list_item1" v-for="(item,index) in ExamList" :key="index" v-else>
					<view class="list_content1">
						<view class="list_content_left">
							<view class="list_content_title">{{item.qbName}}</view>
							<view class="list_content_status" v-show="item.status==2">
								{{item.title_num}}/{{item.title_num}}
							</view>
						</view>
						<view class="list_content_time">
							用时：{{item.hour>=10?item.hour:'0'+item.hour}}:{{item.minute>=10?item.minute:'0'+
							item.minute}}:{{item.second>=10?item.second:'0'+item.second}} |
							开始时间：{{item.createtime}}
						</view>
					</view>
					<view class="list_btm">
						<view class="list_btn" v-show="item.status==2" @click="goJieX(item.id)">查看解析</view>
						<view class="list_btn1" v-show="item.status==1"
							@click="goExam(item.id,item.all_time,item.time_spent,item.title_num)">继续作答</view>
					</view>
				</view>
			</block>
			<!-- 错题本 -->
			<block v-if="typeindex==2">
				<view class="none_msg" v-if="InfoList.length==0">
					<image src="../../static/image/offerxq_img_k@2x.png" mode=""></image>
					<view class="none_title">暂无信息</view>
				</view>
				<view class="test_item" v-for="(item,index) in InfoList" :key="index+'a'" v-else>
					<view class="test_top">
						<view class="test_top_l" @click="goDet(item.id)">题目：{{item.name}} </view>
						<view class="test_top_r">
							<image src="../../static/image/ctb_ico_bj_sel@2x.png" mode="" v-if="item.sign==2"
								@click="ClickBj(item.id,item.sign)"></image>
							<image src="../../static/image/ctb_ico_bj_nor@2x.png" mode="" v-else
								@click="ClickBj(item.id,item.sign)"></image>
						</view>
					</view>
					<view class="test_sel_item" v-for="(items,indexs) in item.answer_list" :key="indexs"
						@click="goDet(item.id)">
						<view class="test_sel_index" :class="{'testactive':item.answer==indexs}">{{indexs}}</view>
						<view class="test_sel_con">{{items}}</view>
					</view>
					<view class="list_btm jl">
						<view class="list_btn" @click="showModal($event,item.qi_id)" data-target="Modal">纠错</view>
						<!-- <view class="list_btn1">提交</view> -->
					</view>
					<view class="test_btm jl" v-show='false'>
						<view class="test_sel_item jl">
							<view class="test_sel1">正确答案:</view>
							<view class="testactive">A</view>
						</view>
						<view class="test_sel_item">
							<view class="test_sel1">您的答案:</view>
							<!-- 错误 -->
							<view class="testactive1">A</view>
							<!-- 正确 -->
							<!-- <view class="testactive2">A</view>	 -->
						</view>
						<view class="test_sel_item">
							<view class="test_sel1">是否正确:</view>
							<view class="test_sel1">错误</view>
						</view>
						<view class="list_btm1">
							<view class="list_btn" @click="showModal" data-target="Modal">纠错</view>
							<!-- <view class="list_btn1">提交</view> -->
						</view>
					</view>
				</view>

			</block>
			<!-- </view> -->
		</scroll-view>
		<!-- 纠错弹窗 -->
		<view class="cu-modal" :class="modalName=='Modal'?'show':''">
			<view class="cu-dialog">
				<view class="cu_title">
					<view></view>
					<view class="text-bold cu-item-title1">试题纠错</view>
					<view class="action1" @click="hideModal">
						<image src="../../static/image/ico_ts_gb@2x.png" mode=""></image>
					</view>
				</view>
				<view class="padding_xl">
					<view class="cu_test_id">我要纠错的题目ID：{{eid}}</view>
					<view class="cu_tip">为方便我们排查错误，请详细描述本题错误</view>
					<view class="cu_sel_item_box">
						<view class="cu_sel_item" v-for="(item,index) in ErrorList" :key="index"
							:class="{'cu_sel_active':itemindex==item.id}" @click="chooseitem(item.id)">
							{{item.name}}
						</view>
					</view>
					<view class="cu_testarea_box">
						<textarea value="" placeholder="请输入纠错内容" placeholder-class="input_class" v-model="content" />
					</view>
				</view>
				<view class="button">
					<view class="cu_btn" @click="goChangeError">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Examinationindex,
		Examinationlist,
		correctList,
		Correcterror,
		signitem,
		cancelsign
	} from '@/api/personal.js'
	export default {
		data() {
			return {
				typeindex: 1,
				modalName1: null,
				modalName: null,
				seltype: 1,
				testindex: '',
				itemindex: 0,
				ExamList: [],
				hour: '',
				second: '',
				minute: '',
				end_second: '',
				InfoList: [],
				ErrorList: [],
				eid: '',
				content: '',
				page: 1,
				pageSize: 10
			}
		},
		onLoad() {
			// this.getRecordList()
			// this.getErrorList()
			this.getErrorClass()
		},
		onShow() {
			this.getRecordList()
			this.getErrorList()
		},
		methods: {
			clickbtn(val) {
				this.typeindex = val
				if (this.typeindex == 1) {
					this.getRecordList()
				}
				if (this.typeindex == 2) {
					this.getErrorList()
				}
				this.$emit('mttesttoggole', val)
			},
			chooseTest(val) {
				this.testindex = val
			},
			chooseitem(val) {
				this.itemindex = val
			},
			showModal(e, id) {
				this.eid = id
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
			// 课程评价
			chooseType(val) {
				this.seltype = val
			},
			goPay() {
				uni.navigateTo({
					url: '../payment/payment'
				})
			},
			// 触底加载
			AddPage() {
				this.pageSize = this.pageSize + 10
				this.getRecordList()
				this.getErrorList()
			},
			// 获取做题记录
			getRecordList() {
				var obj = {
					page: this.page,
					pageSize: this.pageSize
				};
				Examinationindex(obj).then(res => {
					if (res.code == 1) {
						this.ExamList = res.data.data
					}
				});
			},
			goJieX(id) {
				uni.navigateTo({
					url: '../Brush/testEnd?eid=' + id
				})
			},
			goExam(id, alltime, time_spent, title_num) {
				this.end_second = parseInt(alltime - time_spent)
				uni.navigateTo({
					url: '../Brush/testDet?end_second=' + this.end_second + '&eid=' + id + '&titlenum=' +
						title_num + '&time_spend=' + time_spent
				})
			},
			// 错题
			getErrorList() {
				var obj = {
					page: this.page,
					pageSize: this.pageSize
				};
				Examinationlist(obj).then(res => {
					if (res.code == 1) {
						this.InfoList = res.data.data
						console.log(this.InfoList)
					}
				});
			},
			getErrorClass() {
				var obj = {};
				correctList(obj).then(res => {
					if (res.code == 1) {
						this.ErrorList = res.data
						console.log(this.InfoList)
					}
				});
			},
			goDet(id) {
				uni.navigateTo({
					url: 'ErrorDet?id=' + id
				})
			},
			// 试题纠错
			goChangeError() {
				var obj = {
					qi_id: this.eid,
					correct_id: this.itemindex,
					content: this.content
				};
				Correcterror(obj).then(res => {
					if (res.code == 1) {
						this.hideModal()
						this.$msg(res.msg)
						this.eid = ''
						this.correct_id = ''
						this.content = ''
					}
				});
			},
			// 标记
			ClickBj(id, sign) {
				if (sign == 1) {
					var obj = {
						ei_id: id,
					};
					signitem(obj).then(res => {
						if (res.code == 1) {
							this.getErrorList()
						}
					});
				
				} else if (sign == 2) {
					var obj = {
						ei_id: id,
					};
					cancelsign(obj).then(res => {
						if (res.code == 1) {
							this.getErrorList()
						}
					});
				}

			}

		}
	}
</script>

<style>
	.content {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
	}

	.tabber_box {
		width: 100%;
		height: 80rpx;
		margin: auto;
		background-color: #FFFFFF;
		padding: 0 200rpx;
		/* padding-left: 20rpx; */
		position: fixed;
		top: 85rpx;
		/* #ifdef APP-PLUS */
		top: 0;
		/* #endif */
		z-index: 10;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.tabber_item {
		/* width: 50%; */
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		flex-shrink: 0;
	}

	.chooseactive {
		/* width: 50%; */
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.title_line {
		width: 60rpx;
		height: 4rpx;
		background: #FFDD47;
		border-radius: 2rpx;
		margin-top: 5rpx;
	}

	.list_box {
		width: 100%;
		/* height: auto; */
		/* #ifdef APP-PLUS */
		height: 100%;
		/* #endif */
		height: calc(100% - 100rpx);
		margin-top: 100rpx;
		padding-bottom: 30rpx;
		overflow-y: auto;
	}

	.list_item {
		width: 100%;
		height: 290rpx;
		background-color: #FFFFFF;
		padding: 0rpx 30rpx;
		margin-top: 20rpx;
	}

	.list_item1 {
		width: 100%;
		height: 240rpx;
		background-color: #FFFFFF;
		padding: 0rpx 30rpx;
		margin-bottom: 20rpx;
	}

	.list_top {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.list_top_l {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.list_top_r {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FF3B30;
	}

	.list_content {
		width: 100%;
		height: 190rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1rpx solid #F5F5F5;
	}

	.list_content1 {
		width: 100%;
		height: 140rpx;
		padding-top: 30rpx;
	}

	.list_content_l image {
		width: 196rpx;
		height: 130rpx;
		background: #F7F5F6;
		border-radius: 10rpx;
	}

	.list_content_r {
		width: 68%;
		height: 130rpx;
	}

	.list_content_left {
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.list_content_title {
		width: 75%;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		overflow: hidden; //超出的文本隐藏
		text-overflow: ellipsis; //用省略号显示
		white-space: nowrap; //不换行
	}

	.list_content_status {
		width: auto;
		height: 40rpx;
		padding: 0 15rpx;
		background: #FF3B30;
		border-radius: 0px 0px 10rpx 10rpx;
		font-size: 22rpx;
		font-family: PingFang SC;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: -58rpx;
	}

	.list_content_money {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FF3B30;
	}

	.list_content_time {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 10rpx;
	}

	.list_btm {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		border-top: 1rpx solid #F5F5F5;
	}

	.list_btm1 {
		width: 100%;
		height: 100rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}

	.list_btn {
		width: 120rpx;
		height: 40rpx;
		border: 1rpx solid #CCCCCC;
		border-radius: 4rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.list_btn1 {
		width: 120rpx;
		height: 40rpx;
		background: #FFDD47;
		border-radius: 4rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-left: 40rpx;
	}

	/* 试题 */
	.test_item {
		width: 100%;
		height: auto;
		padding: 0rpx 30rpx;
		background-color: #FFFFFF;
		padding-top: 30rpx;
		margin-bottom: 20rpx;
	}

	.test_top_r image {
		width: 22rpx;
		height: 26rpx;
	}

	.test_top {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.test_top_l {
		width: 80%;
		height: auto;
	}

	.test_sel_item {
		width: 100%;
		height: 70rpx;
		display: flex;
		align-items: center;
	}

	.test_sel_index {
		width: 36rpx;
		height: 36rpx;
		border: 1rpx solid #CCCCCC;
		border-radius: 50%;
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 40rpx;
	}

	.testactive {
		width: 36rpx;
		height: 36rpx;
		border: none !important;
		background: #FFDD47;
		border-radius: 50%;
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 40rpx;
	}

	.test_btm {
		width: 100%;
		/* display: flex;
		align-items: center;
		justify-content: flex-end; */
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		border-top: 1rpx solid #F5F5F5;
	}

	.jl {
		margin-top: 15rpx;
	}

	.test_sel1 {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		margin-right: 40rpx;
	}

	.testactive1 {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FF3B30;
	}

	.testactive2 {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #20D43E;
	}

	/* 纠错弹窗 */
	.cu-dialog {
		width: 570rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.cu-item-title {
		font-size: 32rpx;
	}

	.cu-item-title1 {
		width: 100%;
		font-size: 32rpx;
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.action1 image {
		width: 29rpx;
		height: 29rpx;

	}

	.cu_title {
		width: 100%;
		height: 80rpx;
		padding: 0rpx 20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		background: #F5F5F5;

	}

	.button {
		width: 100%;
		height: 100rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.cu_btn {
		width: 250rpx;
		height: 60rpx;
		background: #FFDD47;
		border-radius: 6rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.padding_xl {
		width: 100%;
		height: auto;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		padding: 0 20rpx;
	}

	.cu_close {
		width: 60rpx;
		height: 60rpx;
		position: absolute;
		bottom: 25%;
		right: 45%;
	}

	.cu_test_id {
		width: 100%;
		height: 85rpx;
		display: flex;
		align-items: center;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		border-bottom: 1rpx solid #F5F5F5;
	}

	.cu_tip {
		width: 100%;
		height: 85rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 22rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.cu_sel_item_box {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: flex-start;
		align-items: flex-start;
		flex-wrap: wrap;
	}

	.cu_sel_item {
		width: auto;
		height: 44rpx;
		padding: 0 20rpx;
		border: 1rpx solid #CCCCCC;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
	}

	.cu_sel_active {
		width: auto;
		height: 44rpx;
		padding: 0 20rpx;
		background: #FFFAE6;
		border: 1rpx solid #FFDD47;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
	}

	.cu_testarea_box {
		width: 100%;
		height: 140rpx;
		background: #F2F2F2;
		padding: 20rpx 20rpx;
		margin-top: 10rpx;
		margin-bottom: 9rpx;
	}

	textarea {
		width: 100%;
		height: 100%;
		font-size: 26rpx;
		text-align: start;
	}

	.input_class {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	/* 暂无消息 */
	.none_msg {
		width: 100%;
		height: auto;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		margin-top: 300rpx;
	}

	.none_msg image {
		width: 354rpx;
		height: 253rpx;
	}

	.none_title {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #666666;
		margin-top: 40rpx;
	}
</style>
